<?php

namespace App\Http\Resources\Counter;

use App\Enums\OrderItemType;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class OrderResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        $data = parent::toArray($request);
        $data['table_item'] = null;
        foreach ($data['items'] as $item) {
            if ($item['type'] == OrderItemType::Table->value || $item['type'] == OrderItemType::Table)
                $data['table_item'] = $item;
        }

        return $data;
    }
}
